package com.inossem.warehousemanage_tv.adapter;

import android.content.Context;
import android.view.Gravity;
import android.view.View;

import com.inossem.warehousemanage_tv.R;
import com.inossem.warehousemanage_tv.bean.MenuBean;
import com.inossem.warehousemanage_tv.utils.DensityHelper;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import q.rorbin.badgeview.Badge;
import q.rorbin.verticaltablayout.adapter.TabAdapter;
import q.rorbin.verticaltablayout.widget.TabView;

/**
 * TODO
 *
 * @author 詹建宇
 * @time on 2019/2/13 11:10
 * @email jianyu.zhan@inossem.com
 */
public class MyTabAdapter implements TabAdapter {

    private Context context;
    private List<MenuBean> menus;

    public MyTabAdapter(Context context) {
        this.context = context;
        menus = new ArrayList<>();
        Collections.addAll(menus,
                new MenuBean(R.drawable.b1, R.drawable.c1, "仓库概览")
                , new MenuBean(R.drawable.b2, R.drawable.c2, "待办事项")
                , new MenuBean(R.drawable.b3, R.drawable.c3, "库龄分析")
                , new MenuBean(R.drawable.b5, R.drawable.c5, "作业量分析")
                , new MenuBean(R.drawable.b5, R.drawable.c5, "扫描"));
    }

    @Override
    public int getCount() {
        return menus.size();
    }

    @Override
    public TabView.TabBadge getBadge(int position) {
        return new TabView.TabBadge.Builder().setBadgeNumber(0).setBackgroundColor(0xff2faae5)
                .setOnDragStateChangedListener(new Badge.OnDragStateChangedListener() {
                    @Override
                    public void onDragStateChanged(int dragState, Badge badge, View targetView) {
                    }
                }).build();
    }

    @Override
    public TabView.TabIcon getIcon(int position) {
        MenuBean menu = menus.get(position);
        return new TabView.TabIcon.Builder()
                .setIcon(menu.mSelectIcon, menu.mNormalIcon)
                .setIconGravity(Gravity.START)
                .setIconMargin(DensityHelper.dp2px(context, (float) 5))
                .setIconSize(DensityHelper.dp2px(context, (float) 40), DensityHelper.dp2px(context, (float) 40))
                .build();
    }

    @Override
    public TabView.TabTitle getTitle(int position) {
        MenuBean menu = menus.get(position);
        return new TabView.TabTitle.Builder()
                .setContent(menu.mTitle)
                .setTextSize(36)
                .setTextColor(0xFF004799, 0xFF757575)
                .build();
    }

    @Override
    public int getBackground(int position) {
        return -1;
    }
}
